'use client'; import { useState, type FormEvent } from 'react'; import { REVIEW_COMMENT_LIMIT, REVIEW_DISCOVERY_SOURCE_LIMIT, REVIEW_DISCOVERY_SOURCES, REVIEW_DISPLAY_NAME_LIMIT, REVIEW_MAX_UPLOAD_BYTES } from '@/app/lib/reviews'; async function resizePhoto(file: File): Promise { if (file.size <= REVIEW_MAX_UPLOAD_BYTES && ['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) return file; const image = await createImageBitmap(file).catch(() => null); if (!image) throw new Error('Please choose a JPG, PNG, or WebP photo.'); try { const scale = Math.min(1, 1600 / Math.max(image.width, image.height)); const canvas = document.createElement('canvas'); canvas.width = Math.max(1, Math.round(image.width * scale)); canvas.height = Math.max(1, Math.round(image.height * scale)); const context = canvas.getContext('2d'); if (!context) throw new Error('Could not prepare your photo.'); context.fillStyle = '#fff'; context.fillRect(0, 0, canvas.width, canvas.height); context.drawImage(image, 0, 0, canvas.width, canvas.height); const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.84)); if (!blob || blob.size > REVIEW_MAX_UPLOAD_BYTES) throw new Error('Please choose a smaller photo.'); return new File([blob], 'review-photo.jpg', { type: 'image/jpeg' }); } finally { image.close(); } } export function ReviewForm({ orderId }: { orderId: string }) { const [rating, setRating] = useState(0); const [discoverySource, setDiscoverySource] = useState(''); const [sending, setSending] = useState(false); const [sent, setSent] = useState(false); const [error, setError] = useState(''); const submit = async (event: FormEvent) => { event.preventDefault(); if (sending) return; const form = new FormData(event.currentTarget); const photo = form.get('photo'); setSending(true); setError(''); try { if (photo instanceof File && photo.size) form.set('photo', await resizePhoto(photo)); const res = await fetch(`/api/orders/${orderId}/review`, { method: 'POST', body: form }); const result = await res.json().catch(() => null) as { error?: string } | null; if (!res.ok) throw new Error(result?.error ?? 'Could not submit your review. Try again.'); setSent(true); } catch (error) { setError(error instanceof Error ? error.message : 'Could not submit your review. Try again.'); } finally { setSending(false); } }; if (sent) return

Thank you for sharing. Your review is with the studio for approval.

; return (
Your rating {[1, 2, 3, 4, 5].map(value => ( ))}